<?php

require_once("Model/ModelsInclude.php");

require_once("Layout/header.php");

/*
 * Istanza generica per accesso ad attributi del model.
 */
$c = Cliente::getInstance();
define("PARENT_PAGE_NAME","Clienti");
define("PAGE_NAME","Modifica Cliente");
define("PAGE_TITLE","Visualizza Dettagli&#47;Modifica Cliente");
global $pagesCtrlerEditLink, $pagesEditLink, $pagesAddLink, $pagesRemoveLink;

/*
 * Connessione DB.
 */
$db = new DatabaseManager();
$db->Connect();

/*
 * Stampa dell'header della pagina
 */
printHeader(PAGE_NAME, PAGE_TITLE, $c);

$IDToGet = $_GET["ID"];

$objectToEdit = $c->getFromDB($db, $IDToGet);

if($objectToEdit == NULL)
{
	echo('<p style=\"color:#f00;\"><b>Parametri della richiesta non validi!</b></p>');
	include("Layout/footer.php");
	die();
}

LayoutUtils::printEditPage($db, $objectToEdit, $pagesCtrlerEditLink[PARENT_PAGE_NAME]);

?>

<!-- Tabella associativa della relazione 1xN con offerte -->

<div class="top-bar">
<h1>Offerte inviate:</h1>
</div>
<div class="select-bar-void"></div>

<?php

$thisForeignKey = "idCliente";
$thisForeignValue = $objectToEdit->dataTupla[STD_ID];

define("ASSOC_PAGE_NAME","Offerte");

$c = Offerta::getInstance();
$assocList = $c->getListFromDBByIDCliente($db,$thisForeignValue);

LayoutUtils::print_1xN_AssocModelList($db, $thisForeignKey, $thisForeignValue, $c, $assocList,
		$pagesRemoveLink[ASSOC_PAGE_NAME], $pagesEditLink[ASSOC_PAGE_NAME],
		false, $pagesAddLink[ASSOC_PAGE_NAME]);

?>

<!-- Tabella associativa della relazione 1xN con ordini -->

<div class="top-bar">
<h1>Ordini inviati:</h1>
</div>
<div class="select-bar-void"></div>

<?php

define("ASSOC_PAGE_NAME2","Ordini");

$c2 = Ordine::getInstance();
$assocList2 = $c2->getListFromDBByIDCliente($db,$thisForeignValue);

LayoutUtils::print_1xN_AssocModelList($db, $thisForeignKey, $thisForeignValue, $c2, $assocList2,
		$pagesRemoveLink[ASSOC_PAGE_NAME2], $pagesEditLink[ASSOC_PAGE_NAME2],
		false, $pagesAddLink[ASSOC_PAGE_NAME2]);

include("Layout/footer.php");

?>
